package cn.edu.jxau.core.util;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

/**
 * 时间工具类
 * <p>
 * MangoDai
 * 2017 07 20 2:15 PM
 */
public class DateUtils {
    private static SimpleDateFormat sdf = new SimpleDateFormat("yyyyMM");
    private static SimpleDateFormat sdf2 = new SimpleDateFormat("yyyyMMdd");
    private static SimpleDateFormat sdf4 = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
    private static SimpleDateFormat sdf3 = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss:SSS");
    private static SimpleDateFormat sdf5 = new SimpleDateFormat("yyyy-MM-dd");
    
    public static String getMonthBeforeDate(){
    	Date dNow = new Date();   //当前时间
    	Date dBefore = new Date();
    	Calendar c = Calendar.getInstance();
    	c.setTime(dNow);//把当前时间赋给日历
        c.add(Calendar.DAY_OF_MONTH, -30);
        return sdf4.format(c.getInstance().getTime());
    }
    
    /**
     * 获得当前日期时间
     * @return
     */
    public static String getNowTime() {
        return sdf4.format(new Date());
    }
    
    /**
     * 获得当前日期
     * @return
     */
    public static String getNowDate() {
        return sdf2.format(new Date());
    }
    
    /**
     * 得到存入数据库的当前时间
     * @return
     */
    public static String getNowDateTime() {
        return sdf4.format(new Date());
    }
    
    
    /**
     * 得到现在的月头1号
     * @return
     */
    public static Date getMonthOne() {
        try {
            return sdf2.parse( sdf.format(new Date())+"01");
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return new Date();
    }
    
    /**
     * 得到一星期前的时间
     * @zclong
     * @2017年8月30日
     * @ReturnType: String
     * @return
     */
    public static String getWeekAgoTime (int timeCount) {
        Calendar curr = Calendar.getInstance();
        curr.set(Calendar.DAY_OF_MONTH,curr.get(Calendar.DAY_OF_MONTH)- 7*timeCount);
        Date date=curr.getTime();
        return sdf4.format(date);
    }
    
    /**
     * 将时间格式化
     * @return
     */
    public static String getFormatTime(Object time) {
        return sdf5.format(time);
    }
}
